from .base_model import BaseModel
from django.contrib.auth.models import User
from .classinfo import ClassInfo
from .subject import Subject
from .semester import Semester
from django.db import models

class ClassSubjectAssignment(BaseModel):
    """班级学科分配"""
    class_id = models.ForeignKey(ClassInfo, on_delete=models.CASCADE, related_name='subject_assignments', verbose_name="班级")
    subject = models.ForeignKey(Subject, on_delete=models.CASCADE, related_name='class_assignments', verbose_name="学科")
    teacher = models.ForeignKey(User, on_delete=models.CASCADE, related_name='class_subject_assignments', verbose_name="授课教师")
    semester = models.ForeignKey(Semester, on_delete=models.CASCADE, related_name='class_subject_assignments', verbose_name="学期")

    def __str__(self):
        return f"{self.class_id} - {self.subject.name} "

    class Meta:
        verbose_name = "班级学科分配"
        verbose_name_plural = "班级学科分配"
        unique_together = ('class_id', 'subject', 'semester')